package codeine.mail;

import javax.inject.Inject;

import org.apache.log4j.Logger;

import codeine.jsons.mails.CollectorNotificationJson;
import codeine.jsons.nodes.NodeHelper;
import codeine.jsons.nodes.NodeJson;
import codeine.jsons.project.ProjectJson;
import codeine.jsons.project_status.ProjectStatusList;
import codeine.mongo.IAlertsDatabaseConnector;
import codeine.utils.InetUtils;

public class NotificationDeliverToMongo {

	private static final Logger log = Logger.getLogger(NotificationDeliverToMongo.class);
	@Inject private ProjectStatusList projectStatusList;
	@Inject private IAlertsDatabaseConnector mongoConnector;
	
	public void sendCollectorResult(String collectorName, NodeJson node,
			ProjectJson project, String output) {
		String version = new NodeHelper().getVersionOrNull(projectStatusList, project, node);
		CollectorNotificationJson collectorNotificationJson = new CollectorNotificationJson(collectorName,
				project.name(), output, node, version, InetUtils.getLocalHost().getHostName());
		log.debug("sending " + collectorNotificationJson);
		mongoConnector.put(collectorNotificationJson);
	}

}
